package com.onesports.intelligent.k12.polarlight.common.utils;


import com.onesports.intelligent.k12.polarlight.common.errors.exceptions.BusinessException;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/**
 * @author hmf
 * @date 2021/9/30
 * @description 异常处理
 */
@Component
public class Assert {

    /**
     * 判断表达式是否正确，错误则抛异常
     *
     * @param expression
     * @param message
     */
    public static void isTrue(boolean expression, String message) {
        if (!expression) {
            throw new BusinessException(message);
        }
    }

    /**
     * 判断是否为空，非空就抛异常
     *
     * @param object
     * @param message
     */
    public static void isNull(@Nullable Object object, String message) {
        if (object != null) {
            throw new BusinessException(message);
        }
    }

    /**
     * 判断是否为空，空就抛异常
     *
     * @param object
     * @param message
     */
    public static void notNull(@Nullable Object object, String message) {
        if (object == null) {
            throw new BusinessException(message);
        }
    }

    public static void isFalse(boolean isBuild, String s) {
        if (isBuild) {
            throw new BusinessException(s);
        }
    }
}
